<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>Linux 命令- rmdir | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>Linux 命令- rmdir</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Linux命令/">Linux命令</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;rmdir是常用的命令，该命令的功能是删除空目录，一个目录被删除之前必须是空的。（注意，rm - r dir命令可代替rmdir，但是有很大危险性。）删除某目录时也必须具有对父目录的写权限。     </p>
<h2 id="1．命令格式："><a href="#1．命令格式：" class="headerlink" title="1．命令格式："></a>1．命令格式：</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">rmdir [选项] [目录]</div></pre></td></tr></table></figure>
<h2 id="2．命令功能："><a href="#2．命令功能：" class="headerlink" title="2．命令功能："></a>2．命令功能：</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;该命令从一个目录中删除一个或多个子目录项，删除某目录时也必须具有对父目录的写权限。</p>
<h2 id="3．命令参数："><a href="#3．命令参数：" class="headerlink" title="3．命令参数："></a>3．命令参数：</h2><ul>
<li><ul>
<li>p 递归删除目录dirname，当子目录删除后其父目录为空时，也一同被删除。如果整个路径被删除或者由于某种原因保留部分路径，则系统在标准输出上显示相应的信息。</li>
</ul>
</li>
<li>-v, –verbose  显示指令执行过程 </li>
</ul>
<h2 id="4．命令实例："><a href="#4．命令实例：" class="headerlink" title="4．命令实例："></a>4．命令实例：</h2><h3 id="实例1：rmdir-不能删除非空目录"><a href="#实例1：rmdir-不能删除非空目录" class="headerlink" title="实例1：rmdir 不能删除非空目录"></a>实例1：rmdir 不能删除非空目录</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">rmdir doc</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div></pre></td><td class="code"><pre><div class="line">[root@localhost scf]<span class="comment"># tree</span></div><div class="line">.</div><div class="line">|-- bin</div><div class="line">|-- doc</div><div class="line">|   |-- info</div><div class="line">|   `-- product</div><div class="line">|-- lib</div><div class="line">|-- logs</div><div class="line">|   |-- info</div><div class="line">|   `-- product</div><div class="line">`-- service</div><div class="line">    `-- deploy</div><div class="line">        |-- info</div><div class="line">        `-- product</div><div class="line"> </div><div class="line">12 directories, 0 files</div><div class="line">[root@localhost scf]<span class="comment"># rmdir doc</span></div><div class="line">rmdir: doc: 目录非空</div><div class="line">[root@localhost scf]<span class="comment"># rmdir doc/info</span></div><div class="line">[root@localhost scf]<span class="comment"># rmdir doc/product</span></div><div class="line">[root@localhost scf]<span class="comment"># tree</span></div><div class="line">.</div><div class="line">|-- bin</div><div class="line">|-- doc</div><div class="line">|-- lib</div><div class="line">|-- logs</div><div class="line">|   |-- info</div><div class="line">|   `-- product</div><div class="line">`-- service</div><div class="line">    `-- deploy</div><div class="line">        |-- info</div><div class="line">        `-- product</div><div class="line"> </div><div class="line">10 directories, 0 files</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明：</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;rmdir 目录名 命令不能直接删除非空目录</p>
<h3 id="实例2：rmdir-p-当子目录被删除后使它也成为空目录的话，则顺便一并删除"><a href="#实例2：rmdir-p-当子目录被删除后使它也成为空目录的话，则顺便一并删除" class="headerlink" title="实例2：rmdir -p 当子目录被删除后使它也成为空目录的话，则顺便一并删除"></a>实例2：rmdir -p 当子目录被删除后使它也成为空目录的话，则顺便一并删除</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">rmdir -p logs</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div></pre></td><td class="code"><pre><div class="line">[root@localhost scf]<span class="comment"># tree</span></div><div class="line">.</div><div class="line">|-- bin</div><div class="line">|-- doc</div><div class="line">|-- lib</div><div class="line">|-- logs</div><div class="line">|   `-- product</div><div class="line">`-- service</div><div class="line">    `-- deploy</div><div class="line">        |-- info</div><div class="line">        `-- product</div><div class="line"> </div><div class="line">10 directories, 0 files</div><div class="line">[root@localhost scf]<span class="comment"># rmdir -p logs</span></div><div class="line">rmdir: logs: 目录非空</div><div class="line">[root@localhost scf]<span class="comment"># tree</span></div><div class="line">.</div><div class="line">|-- bin</div><div class="line">|-- doc</div><div class="line">|-- lib</div><div class="line">|-- logs</div><div class="line">|   `-- product</div><div class="line">`-- service</div><div class="line">    `-- deploy</div><div class="line">        |-- info</div><div class="line">        `-- product</div><div class="line"> </div><div class="line">9 directories, 0 files</div><div class="line">[root@localhost scf]<span class="comment"># rmdir -p logs/product</span></div><div class="line">[root@localhost scf]<span class="comment"># tree</span></div><div class="line">.</div><div class="line">|-- bin</div><div class="line">|-- doc</div><div class="line">|-- lib</div><div class="line">`-- service</div><div class="line">`-- deploy</div><div class="line">        |-- info</div><div class="line">        `-- product</div><div class="line"> </div><div class="line">7 directories, 0 files</div></pre></td></tr></table></figure>

	

	
		<span class="different-posts"><a href="/2017/10/12/2. Linux 命令/5. Linux 命令-rmdir/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
